#include "perseus.h"
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

#define TEST0 "PERSEUS: this is a test"

int main(int argc, char * argv[]) 
 {
  libperseus_hl_t lht;
  unsigned char *encoded_data, *decoded_data;
  unsigned long int encoded_data_size, decoded_data_size;
  unsigned char *clair, *test;

  memset(&lht, '\0', sizeof(libperseus_hl_t));

  if (argc > 1)
    test = argv[1];
  else
    test = TEST0;
  clair = strdup(test);
  
  fprintf(stderr, "CLAIR = %s\n", clair);

  perseus_init( &lht);
  fprintf(stderr, "Initialisation done\n");
  
  encoded_data = perseus_code( &lht, clair, (unsigned long int)(strlen((char *)clair)), &encoded_data_size );
  if (encoded_data == NULL) {
    fprintf(stderr, "Error ....\n");
      exit(-1);
  }
  fprintf(stderr, "ENCODED DATA @ 0x%lx %lx\n", (unsigned long)(encoded_data), encoded_data_size);
  
  decoded_data = perseus_decode( &lht, encoded_data, encoded_data_size, &decoded_data_size );
  if (decoded_data == NULL) {
    fprintf(stderr, "Error ....\n");
    exit(-1);
  }
  fprintf(stderr, "DECODED DATA @ %s 0x%lx %lx\n", decoded_data, (unsigned long)(decoded_data), decoded_data_size);

  printf("%s\n", decoded_data);

  perseus_destroy( &lht );
  free(clair);

  return(0);
 }
